import pandas as pd
from matplotlib import pyplot as plt
import textwrap
plt.rcParams['font.sans-serif']=['SimHei']




data=pd.read_excel("./data4_4_classify_job/算法成都.xlsx")
data=data.drop("Unnamed: 0",axis=1)
salary_top10_1=data.sort_values(by="salary",ascending=False)
salary_top10_1=salary_top10_1.drop_duplicates("company_name")
salary_top10_1=salary_top10_1.drop_duplicates("salary").head(10)
salary_top10_2=salary_top10_1[["company_name","salary"]].reset_index(drop=True)
max_width=5
salary_top10_2['company_name'] = salary_top10_2['company_name'].apply(lambda x:"\n".join(textwrap.fill(x,max_width).split()))
colors = ['g','r','orange','c','m']
salary_top10_2.plot(kind='bar',x='company_name',y='salary',width=0.5,color=colors)
#转为列表
salary_top10_3=salary_top10_2['salary'].tolist()
for x,y in enumerate(salary_top10_3):
    plt.text(x,y+100,y,ha='center',fontsize=12)
plt.ylim(15000,30000)
plt.title("罗坛作业：成都算法岗位工资排名top10")
plt.xlabel('公司名称',fontsize=16)
plt.ylabel('工资',fontsize=16)
plt.xticks(fontsize=7,rotation=0)
plt.tight_layout()
plt.savefig('./Picture/5-2成都地区算法岗位工资排名top10的公司')
plt.show()